import _ from 'lodash';
import type { App } from 'vue';
import { SvgIcon } from './SvgIcon';

/**
 * @description 自动将 ./src/components/global 下的组件注册成为全局组件
 * @param {vue} app 当前应用实例
 * @returns {void} void
 */
export function registeGlobalComponent(app: App): void {
  const files = require.context('./global', true, /\.(vue|ts)$/);
  files.keys().forEach(key => {
    const config = files(key);
    const name = _.kebabCase(key.replace(/^\.\//, '').replace(/\.\w+$/, ''));
    app.component(name, config.default || config);
  });

  // svg 组件
  app.component(SvgIcon.name, SvgIcon);
}
